//
//  HomeAPI.swift
//  casdon_swiftUI
//
//  Created by ww on 2025/5/2.
//

import Foundation


enum HomeAPI {
    struct Banner: API {
        typealias Response = [Data]
        struct Data: Decodable {
            let link: String
            let picture: String
            let position: Int
            let showEndTime: Int
            let showStartTime: Int
            let title: String
        }
        
        let body: EmptyBody?
        let path: String = "/v1/recipe/getAppHomeBanner"
        let method: HTTPMethod = .GET
        var headers: [String: String] = ["Content-Type": "application/json",  "timestamp": Date().milliStamp, "clientId": APP_CLIENTID]
        let query: [String: String]? = nil
        let pathValues: [String: String]? = nil
        let requiresEncryption: Bool = false
        
        
        func withUpdatedHeaders(_ headers: [String: String]) -> Self {
            var copy = self
            copy.headers.merge(headers) { (current, _) in current }
            return copy
        }
    }
    
    // 获取用户信息
    struct UserInfo: API {
        struct Response: Decodable {
            let appVersion: String
            let avatar: String
            let birthday: String?
            let deviceToken: String
            let email: String
            let gender: Int
            let id: String
            
            let iotPlatform: String?
            let model: String
            let nickname: String
            let osName: String
            let osVersion: String
            let regionCode: String
            let registryTime: Int
            
            let tags: String?
            let tenantId: String?
            let userId: String
            let userName: String
            let uuid: String
            let youzanOpenid: String?
            let youzanAccessToken: String?
            
            let ciotAccessToken: String?
            let clientid: String?
        }
        
        init(userId: String) {
            self.userId = userId
            self.path = self.path + userId;
            self.body = nil
        }
        let userId: String
        let body: EmptyBody?
        var path: String = "/v1/users/getInfoByUserId/"
        let method: HTTPMethod = .GET
        var headers: [String: String] = ["Content-Type": "application/json", "timestamp": Date().milliStamp, "clientId": APP_CLIENTID]
        let query: [String: String]? = nil
        let pathValues: [String: String]? = nil
        let requiresEncryption: Bool = false
        
        func withUpdatedHeaders(_ headers: [String: String]) -> Self {
            var copy = self
            copy.headers.merge(headers) { (current, _) in current }
            return copy
        }
    }
}
